import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

//重写路由的push和replace方法防止报错
const originalPush = Router.prototype.push;
Router.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err);
};
const originalReplace = Router.prototype.replace;
Router.prototype.replace = function replace(location) {
    return originalReplace.call(this, location).catch(err => err);
};

const routes = [
    {
        path: "/",
        component: () => import("@/pages/Main.vue"),
        // component: resolve => require(["@/pages/Main.vue"], resolve),
        name: "MainBase",
        children: [
            {
                path: "/mainPage",
                component: () => import('@/pages/MainPage.vue'),
                // component: resolve => require(["@/pages/MainPage.vue"], resolve),
                name: "MainPage"
            },
            {
                path: "/subPage1",
                component: () => import('@/pages/SubPage1.vue'),
                // component: resolve => require(["@/pages/SubPage1.vue"], resolve),
                name: "SubPage1"
            },
            {
                path: "/subPage2",
                component: () => import('@/pages/SubPage2.vue'),
                // component: resolve => require(["@/pages/SubPage2.vue"], resolve),
                name: "SubPage2"
            },
            {
                path: "/default",
                component: () => import("@/pages/Default.vue"),
                // component: resolve => require(["@/pages/Default.vue"], resolve),
                name: "Default",
            },
        ]
    },
    {
        path: "/qrcodePage",
        component: () => import("@/pages/QrcodePage.vue"),
        name: "QrcodePage",
    },
]

export default new Router({
    routes
});